package com.baizhi.cmfz.service.impl;

import com.baizhi.cmfz.dao.GuruDao;
import com.baizhi.cmfz.entity.Guru;
import com.baizhi.cmfz.service.GuruService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
@Service
public class GuruServiceImpl implements GuruService {
    @Autowired
    private GuruDao guruDao;
    @Override
    public Map showAllGuru(int page, int limit) {
        int offset=(page-1)*limit;
        List<Guru> list=guruDao.showAllGuru(offset,limit);
        int count=guruDao.showCount();
        Map map=new HashMap();
        if(count>0){
            map.put("data",list);
            map.put("count",count);
            map.put("code",0);
            map.put("msg","");
        }
        return map;
    }

    @Override
    public Map insertGuru(Guru guru) {
        int count=guruDao.insertGuru(guru);
        Map map=new HashMap();
        if(count>0){
            map.put("isInsert","添加成功");
        }else {
            map.put("isInsert","添加失败");
        }
        return  map;
    }

    @Override
    public Map deleteGuru(int id) {
        int count=guruDao.deleteGuru(id);
        Map map=new HashMap();
        if(count>0){
            map.put("isDelete","删除成功");
        }else {
            map.put("isDelete","删除失败");
        }
        return  map;
    }

    @Override
    public Guru showOne(int id) {
        return guruDao.showOne(id);
    }

    @Override
    public Map updateGuru(Guru guru) {
        int count=guruDao.updateGuru(guru);
        Map map=new HashMap();
        if(count>0){
            map.put("isUpdate","修改成功");
        }else {
            map.put("isUpdate","修改失败");
        }
        return  map;
    }
}
